package com.example.yls.demoa;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

public class EditText_Activity extends AppCompatActivity {
        private EditText editText;
        private CheckBox checkBox;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text_);
        //初始化
        editText=findViewById(R.id.edit1);
        checkBox=findViewById(R.id.checkbox);
        //设置光标不可见，editText.setCursorVisible(false);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                if(isChecked){
                    //显示明文--设置转化方式的实例对象
                    editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
                }else{
                    //显示密文
                    editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
                editText.setSelection(editText.getText().length());
            }
        });
    }
}
